package com.brickworkers.codemaker.domain;

import java.rmi.NoSuchObjectException;
import java.util.Set;

import com.brickworkers.codemaker.utils.StringUtils;

/**
 * 表的列信息
 * @author brickworker
 *
 */
public class Row {
	
	
	private String rowName;
	private String rowNameLowcase;
	private String rowNameUpcase;
	private String description;
	private Type type;
	
	//第一个小写
	private String formatRowName;
	
	//第一个大写
	private String formatRowNameFirstUpcase;
	
	/**
	 * 根据java.sql.Types的类型对应表设置的枚举
	 * 其中包括列最常用的字段类型
	 * @author brickworker
	 *
	 */
	public static enum Type{
		
		VARCHAR(12, "String"), INTEGER(4,"Integer"), BIGINT(-5,"Long"), FLOAT(6,"Float"), DOUBLE(8,"Double"), DECIMAL(3,"Decimal"),  NULL(0,"Null"), LONGVARCHAR(-1, "String");
		private int value;
		public String op;
		
		private Type(int value, String op) {
			this.value = value;
			this.setOp(op);
		}
		
		public int value(){
			return this.value;
		}
		
		
		public static Type getType(int i){
			Type[] types = Type.values();
			for (Type type : types) {
				if(i == type.value){
					return type;
				}
			}
			throw new RuntimeException("未发现对应的Type类型，请往Type枚举中添加该int值：" + i +" 所定义的Type");
		}

		public String getOp() {
			return op;
		}

		public void setOp(String op) {
			this.op = op;
		}
	}
	
	
	public static class Builder{
		private String rowName;
		private String rowNameLowcase;
		private String rowNameUpcase;
		private String description;
		private Type type;
		public Builder(String rowName, Type type){
			this.rowName = rowName;
			this.type = type;
		}
		
		public Builder rowNameLowcase(String rowNameLowcase){
			this.rowNameLowcase = rowNameLowcase;
			return this;
		}
		
		public Builder rowNameUpcase(String rowNameUpcase){
			this.rowNameUpcase = rowNameUpcase;
			return this;
		}
		
		public Builder description(String description){
			this.description = description;
			return this;
		}
		
		public Row build(){
			return new Row(this);
		}
		
		
	}
	
	private Row(Builder builder){
		rowName = builder.rowName;
		formatRowName = StringUtils.getFormatRowName(rowName);
		formatRowNameFirstUpcase = formatRowName.substring(0,1).toUpperCase() + formatRowName.substring(1);
		setType(builder.type);
		setRowNameLowcase(builder.rowNameLowcase);
		setRowNameUpcase(builder.rowNameUpcase);
		description = builder.description;
	}
	
	
	@Override
	public String toString() {
		return " rowNmae:" + rowName + " type:" + getType() + " description:" + getDescription();
	}


	public Type getType() {
		return type;
	}


	public void setType(Type type) {
		this.type = type;
	}


	public String getRowNameLowcase() {
		return rowNameLowcase;
	}


	public void setRowNameLowcase(String rowNameLowcase) {
		this.rowNameLowcase = rowNameLowcase;
	}


	public String getRowNameUpcase() {
		return rowNameUpcase;
	}


	public void setRowNameUpcase(String rowNameUpcase) {
		this.rowNameUpcase = rowNameUpcase;
	}


	public String getFormatRowName() {
		return formatRowName;
	}


	public void setFormatRowName(String formatRowName) {
		this.formatRowName = formatRowName;
	}


	public String getFormatRowNameFirstUpcase() {
		return formatRowNameFirstUpcase;
	}


	public void setFormatRowNameFirstUpcase(String formatRowNameFirstUpcase) {
		this.formatRowNameFirstUpcase = formatRowNameFirstUpcase;
	}


	public String getDescription() {
		return description;
	}


	public void setDescription(String description) {
		this.description = description;
	}
}
